#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace SkyBurner
{
    public class SkyBurnerHUD : BaseObject
    {
        Texture2D m_energyTexture; 
        Texture2D m_rocketTexture;
        Texture2D m_shieldTexture;

        public SkyBurnerHUD(BaseGame game)
            : base(game)
        {
            m_Game.RegisterObject(this);

            m_energyTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Textures\\HUD\\StarfighterEnergy_128");
            m_rocketTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Textures\\HUD\\StarfighterRocket_48");
            m_shieldTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Textures\\HUD\\shield_bar");  
        }

        public override void OnDeviceReset()
        {
            base.OnDeviceReset();

            m_energyTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Textures\\HUD\\StarfighterEnergy");
            m_rocketTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Textures\\HUD\\StarfighterRocket_48");
            m_shieldTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Textures\\HUD\\shield_bar");  
        }

        public void Draw(GameTime gameTime)
        {
            m_Game.SpriteBatch.Begin();
            
            // draw starfighter energy bar
            int nEnergyWidth = (m_energyTexture.Width * SkyBurnerGlobal.EnergyValue / 100);

            Rectangle rectSource = new Rectangle(m_energyTexture.Width - nEnergyWidth, 
                                                 0, 
                                                 nEnergyWidth, 
                                                 m_energyTexture.Height);
            Vector2 pos = new Vector2(10 + m_energyTexture.Width - nEnergyWidth,
                                      m_Game.GraphicsDevice.Viewport.Height - m_energyTexture.Height - 20);

            m_Game.SpriteBatch.Draw(m_energyTexture, pos, rectSource, Color.White);
            
            // draw starfighter shiled bar...
            int nShieldWidth = (m_energyTexture.Width * SkyBurnerGlobal.ShieldValue / 100);
            m_Game.SpriteBatch.Draw(m_shieldTexture,
                               new Rectangle(10 + m_energyTexture.Width - nShieldWidth, m_Game.GraphicsDevice.Viewport.Height - 10, nShieldWidth, 5),
                               new Rectangle(0, 0, m_shieldTexture.Width, 5),
                               Color.White);

            // draw rockets...
            for (int i = 1; i <= SkyBurnerGlobal.RocketCount; i++)
            {
                Vector2 vPos = new Vector2(m_Game.GraphicsDevice.Viewport.Width - 10 - (i * m_rocketTexture.Width), 
                                           m_Game.GraphicsDevice.Viewport.Height - m_rocketTexture.Height - 10);
                m_Game.SpriteBatch.Draw(m_rocketTexture, vPos, Color.White);
            }

            m_Game.SpriteBatch.End();
             
            // draw score/hiscore labels and numbers...
            m_Game.BitmapFont.Print(10, 10, String.Format("score  {0:D}", SkyBurnerGlobal.Score), 20);
            m_Game.BitmapFont.Print(400, 10, String.Format("hiscore  {0:D}", SkyBurnerGlobal.HiScore), 20);

            // draw fps
            m_Game.BitmapFont.Print(10, 40, String.Format("fps {0:D}", m_Game.FPS), 20);
#if false
            m_Game.BitmapFont.Print(10, 40, String.Format("fps {0:D}", m_Game.FPS), 20);
            m_Game.BitmapFont.Print(10, 65, String.Format("sec {0:D}", gameTime.TotalGameTime.Seconds), 20);
#endif            
        }
    }
}
